//
//  WmcEditWatermarkSettingCell.swift
//  YPWatermarkCamera
//
//  Created by 赵新 on 2022/3/11.
//

import UIKit

extension WmcEditWatermarkSettingCell {
    struct Model {
        enum SettingType {
            case alpha
            case size

            struct Info {
                var iconImage: UIImage
                var title: String
            }

            var info: Info {
                switch self {
                case .alpha:
                    return .init(iconImage: "edit_alpha".wmc_image, title: "水印透明度")
                case .size:
                    return .init(iconImage: "edit_size".wmc_image, title: "水印大小")
                }
            }
        }

        var settingType: SettingType
        var value: WmcWatermarkDetailModel
        
        /// 转换
        var wmcBasicItem: WmcButtonItemType.EditWMBasicItem {
            switch settingType {
            case .alpha: return .alpha
            case .size: return .size
            }
        }
    }
}

// MARK: - [WmcEditWatermarkSettingCell]

class WmcEditWatermarkSettingCell: WmcBaseTableCell {
    lazy var valueLabel: UILabel = {
        let label = UILabel.YP.Create(font: 14, color: UIColor.wmc_grayH2_323233, alignment: .right)
        return label
    }()

    lazy var iconImageView: UIImageView = {
        let imageView = UIImageView()
        imageView.contentMode = .scaleAspectFit
        return imageView
    }()

    override func makeUI() {
        addSubview(iconImageView)
        iconImageView.snp.makeConstraints { make in
            make.centerY.equalToSuperview()
            make.left.equalTo(Wmc_standardEdge.left)
            make.size.equalTo(18.wmc_autoHor)
        }

        titleLabel.font = 14.yp.uiFont(weight: .medium)
        titleLabel.textColor = UIColor.wmc_grayH2_323233
        titleLabel.textAlignment = .left
        addSubview(titleLabel)
        titleLabel.snp.makeConstraints { make in
            make.top.bottom.equalToSuperview()
            make.left.equalTo(iconImageView.snp.right).offset(8)
            make.right.equalTo(self.snp.centerX)
        }

        addSubview(arrowImageView)
        arrowImageView.snp.makeConstraints { make in
            make.centerY.equalToSuperview()
            make.right.equalTo(-Wmc_standardEdge.right)
            make.size.equalTo(17)
        }

        addSubview(valueLabel)
        valueLabel.snp.makeConstraints { make in
            make.top.bottom.equalToSuperview()
            make.right.equalTo(arrowImageView.snp.left).offset(-8)
            make.left.equalTo(self.snp.centerX)
        }

        addSubview(lineView)
        lineView.snp.makeConstraints { make in
            make.bottom.equalToSuperview()
            make.height.equalTo(0.5)
            make.left.equalTo(iconImageView.snp_leftMargin)
            make.right.equalTo(arrowImageView.snp_rightMargin)
        }
    }

    /// 配置
    func configModel(_ model: Model) {
        iconImageView.image = model.settingType.info.iconImage
        titleLabel.text = model.settingType.info.title
        switch model.settingType {
        case .alpha: // 透明度
            valueLabel.text = "\(model.value.alpha)%"
            
        case .size:
            valueLabel.text = model.value.scaleSize.info.title
        }
    }
}
